﻿namespace USU.MetricsMonitor.DiffParser
{
	/// <summary>
	/// This structure represents the range of lines in the file
	/// </summary>
	public struct Range
	{
		public ulong StartLine { get; set; }
		public ulong EndLine { get; set; }
	}

	/// <summary>
	/// Called by DiffParser at the start of new chunk
	/// </summary>
	/// <param name="oldFile">Old file name as specified in the chunk header</param>
	/// <param name="oldRange">Old file lines range affected by the chunk</param>
	/// <param name="newFile">New file name from the chunk header</param>
	/// <param name="newRange">New file lines range</param>
	public delegate void ProcessHunkStart(string oldFile, Range oldRange, string newFile, Range newRange);

	/// <summary>
	/// Called by the DiffParser at the end of current chunk
	/// </summary>
	public delegate void ProcessHunkEnd();

	/// <summary>
	/// Process a line of the diff, that may be context line, deleted line or added line
	/// </summary>
	/// <param name="text">Context line contents</param>
	public delegate void ProcessLine(string text);

	/// <summary>
	/// Structure representing the processor of the diff. Null values are permitted
	/// and indicate that the processor ignores corresponding event
	/// </summary>
	public struct DiffProcessor
	{
		private ProcessHunkStart hsh;
		public ProcessHunkStart HunkStartHandler
		{
			get { return hsh ?? ((of,or,nf,nr) => { return; }); }
			set { hsh = value; }
		}

		private ProcessHunkEnd heh;
		public ProcessHunkEnd HunkEndHandler
		{
			get { return heh ?? (() => { return; }); }
			set { heh = value; }
		}

		private ProcessLine clh;
		/// <summary>
		/// Processor for context lines, e.g. lines that are near the change and not modified themselves
		/// </summary>
		public ProcessLine ContextLineHandler
		{
			get { return clh ?? (_ => { return; }); }
			set { clh = value; }
		}

		private ProcessLine alh;
		/// <summary>
		/// Processor for deleted lines
		/// </summary>
		public ProcessLine DeletedLineHandler
		{
			get { return alh ?? (_ => { return; }); }
			set { alh = value; }
		}

		private ProcessLine dlh;
		/// <summary>
		/// Processor for added lines
		/// </summary>
		public ProcessLine AddedLineHandler
		{
			get { return dlh ?? (_ => { return; }); }
			set { dlh = value; }
		}
	}
}
